﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Text;

namespace Voodoo.SharePoint.ReadUnreadMarks
{
    public class ReadUnreadFarmSettings : SPPersistedObject
    {
        public static Guid SETTINGS_ID = new Guid("{53BA8F00-83CE-4980-9EFF-1522CEDE093B}");

        [Persisted]
        private int _DocumentTrackerBackgroundThreadCount = 0;

        [Persisted]
        private bool _WriteDirect = false;

        [Persisted]
        private bool _TrackDocuments = false;

        [Persisted]
        private bool _TrackOfficeDocuments = false;

        public ReadUnreadFarmSettings(string name, SPPersistedObject parent)
            : base(name, parent)
        {
        }
        public ReadUnreadFarmSettings(string name, SPPersistedObject parent, Guid id)
            : base(name, parent, id)
        {
            System.Diagnostics.Trace.WriteLine(base.Farm.Name);
        }

        public ReadUnreadFarmSettings()
            : base()
        {
        }

        public bool WriteDirect
        {
            get { return _WriteDirect; }
            set
            {
                _WriteDirect = value;
                if (!_WriteDirect)
                {
                    if (TrackDocuments) TrackDocuments = false;
                    if (TrackOfficeDocuments) TrackOfficeDocuments = false;
                }
            }
        }

        public int DocumentTrackerBackgroundThreadCount
        {
            get { return _DocumentTrackerBackgroundThreadCount; }
            set { _DocumentTrackerBackgroundThreadCount = value; }
        }

        public bool TrackDocuments
        {
            get
            {
                if (!WriteDirect) return false;
                return _TrackDocuments;
            }
            set
            {
                _TrackDocuments = value;
                if (_TrackDocuments)
                {
                    if (!WriteDirect) WriteDirect = true;
                }
            }
        }

        public bool TrackOfficeDocuments
        {
            get
            {
                if (!WriteDirect) return false;
                if (!TrackDocuments) return false;
                return _TrackOfficeDocuments;
            }
            set
            {
                _TrackOfficeDocuments = value;
                if (_TrackOfficeDocuments)
                {
                    if (!WriteDirect) WriteDirect = true;
                    if (!TrackDocuments) TrackDocuments = true;
                }
            }
        }
    }
}
